package com.hyts.serialize.json.Jsonlib;

import com.hyts.serialize.json.JsonSerializeHandler;
import net.sf.json.JSONObject;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.serialize.json.Jsonlib
 * author:Libo/Alex
 * create-date:2019-06-28 17:47
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
public class JsonLibSerializeHandler implements JsonSerializeHandler<JSONObject> {


    @Override
    public <P> JSONObject buildJSONObject(P param) {
        return JSONObject.fromObject(param);

    }

    @Override
    public <P> String buildJSONString(P param) {
        return JSONObject.fromObject(param).toString();
    }

    @Override
    public <P> JSONObject buildJSONObject(String jsonStr) {
        return JSONObject.fromObject(jsonStr);
    }

    @Override
    public <P> P buildBean(String jsonStr, Class<P> clazzType) {
        return (P) JSONObject.toBean(JSONObject.fromObject(jsonStr),clazzType);
    }

    @Override
    public Object buildBean(String jsonStr) {
        return buildBean(jsonStr,Object.class);
    }
}
